package com.yxhl.zoume.core.tripsmgmt.ui.activity;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.View;
import android.widget.FrameLayout;

import com.yxhl.protobuf.BizOrderResponse;
import com.yxhl.protobuf.StationEntry;
import com.yxhl.zoume.R;
import com.yxhl.zoume.UIConstants;
import com.yxhl.zoume.common.ui.activity.base.BaseActivityWithToolBar;
import com.yxhl.zoume.core.func.map.ui.fragment.ZouMeBusUpPointFragment;
import com.yxhl.zoume.core.tripsmgmt.info.ZouMeBusMapEntrance;
import com.yxhl.zoume.core.tripsmgmt.ui.fragment.tripsdetail.ZouMeBusStationPositionFragment;

import java.io.Serializable;
import java.util.List;

import butterknife.BindView;

/**
 * 定制巴士行程详情 ,位置信息地图页
 */
public class BusMapContainerActivity extends BaseActivityWithToolBar {
    private static final String TAG = "BusMapContainerActivity";

    @BindView(R.id.frame_custom_bus_station_map_body)
    FrameLayout stationMapBodyFrame;

    //arguments
    private ZouMeBusMapEntrance mEntrance;
    //选择乘车站点的信息
    private List<StationEntry> mUpPoints;
    //定制巴士订单详情
    private BizOrderResponse mBizOrderResponse;

    public static Intent getCallingIntent(Activity activity, List<StationEntry> upPoints, ZouMeBusMapEntrance entrance) {
        Intent intent = new Intent(activity, BusMapContainerActivity.class);
        intent.putExtra(UIConstants.TripContainer.INTENT_KEY_ZOUME_BUS_MAP_ENTRANCE, entrance);
        intent.putExtra(UIConstants.TripContainer.INTENT_KEY_ZOUME_BUS_MAP_UP_POINTS, (Serializable) upPoints);
        return intent;
    }

    public static Intent getCallingIntent(Activity activity, BizOrderResponse bizOrderResponse, ZouMeBusMapEntrance entrance) {
        Intent intent = new Intent(activity, BusMapContainerActivity.class);
        intent.putExtra(UIConstants.TripContainer.INTENT_KEY_ZOUME_BUS_MAP_ENTRANCE, entrance);
        intent.putExtra(UIConstants.TripContainer.INTENT_KEY_BUS_MAP_CONTAINER_ORDER_DETAIL, bizOrderResponse);
        return intent;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        handleIntent();
        initializeShow();
    }

    private void handleIntent() {
        Intent intent = getIntent();
        if (intent != null) {
            mEntrance = (ZouMeBusMapEntrance) intent.getSerializableExtra(UIConstants.TripContainer.INTENT_KEY_ZOUME_BUS_MAP_ENTRANCE);
            mUpPoints = (List<StationEntry>) intent.getSerializableExtra(UIConstants.TripContainer.INTENT_KEY_ZOUME_BUS_MAP_UP_POINTS);
            mBizOrderResponse = (BizOrderResponse) intent.getSerializableExtra(UIConstants.TripContainer.INTENT_KEY_BUS_MAP_CONTAINER_ORDER_DETAIL);
        }
    }

    private void initializeShow() {
        addFragment(R.id.frame_custom_bus_station_map_body, fragmentProvider());
    }

    private Fragment fragmentProvider() {
        Fragment fragment;
        switch (mEntrance) {
            case ZOUME_BUS_ORDER:
                fragment = ZouMeBusUpPointFragment.newInstance(mUpPoints);
                break;
            case ZOUME_BUS_TRIP_MANAGEMENT:
                fragment = ZouMeBusStationPositionFragment.newInstance(mBizOrderResponse);
                break;
            default:
                fragment = ZouMeBusUpPointFragment.newInstance(mUpPoints);
        }
        return fragment;
    }

    @Override
    public void onBackPressed() {
        super.onBackPressed();
    }

    @Override
    protected void onHeaderLeftClick(View view) {
        onBackPressed();
    }

    @Override
    protected void onHeaderRightClick(View view) {

    }

    @Override
    protected int getLayoutResId() {
        return R.layout.activity_custom_bus_station_map;
    }

    @Override
    protected void initializeInjector() {

    }
}
